import model from '@backend/model'
import { STATES } from "../includes/public/enums";

export async function initData(){
    await initPluginsData()
    await initChatData()
}

async function initChatData(){    
    const { Chat } = await model('Chat')
    const crec = await Chat.find({ where: { code: 'first_chat_code'}})

    if(crec.length>0) return;    
    Chat.save(Chat.create({
        model: 'gpt-3.5-turbo-16k-0613',
        title: '文心一言-对话'
    }));

    Chat.save(Chat.create({
        model: 'gpt-3.5-turbo-16k-0613',
        title: 'chatGPT对话'
    }));

    Chat.save(Chat.create({
        model: 'gpt-3.5-turbo-16k-0613',
        title: '本地chatGLM对话'
    }));

    Chat.save(Chat.create({
        model: 'gpt-3.5-turbo-16k-0613',
        title: '专业知识库-股票分析'
    }));

    Chat.save(Chat.create({
        model: 'gpt-3.5-turbo-16k-0613',
        title: '中国法律知识库'
    }));

    Chat.save(Chat.create({
        model: 'gpt-3.5-turbo-16k-0613',
        title: '中医问答'
    }));
}

async function initPluginsData(){
    const { Plugins } = await model('Plugins')
    const rec = await Plugins.find({ where: { plugin_tag: 'chat-sys-plugin'}})

    if(rec.length>0) return;

    const plg = Plugins.create({
        plugin_tag: 'chat-sys-plugin',
        plugin_name: 'chat-sys-plugin',
        is_menu: true,
        status: STATES.ACTIVATE, 
        menu_setting: JSON.stringify({
            icon: 'cup-hot-fill',
            logo: '',
            tip: 'chat',
            type: 'menu-chat'
        })
    });
    Plugins.save(plg)

    Plugins.save(Plugins.create({
        plugin_tag: '22222',
        plugin_name: '22222',
        is_menu: true,
        status: STATES.ACTIVATE, 
        menu_setting: JSON.stringify({
            icon: 'kanban-fill',
            logo: '',
            tip: 'relevance',
            type: 'sys'
        })
    }))

    Plugins.save(Plugins.create({
        plugin_tag: '33333',
        plugin_name: '33333',
        is_menu: true,
        status: STATES.ACTIVATE, 
        menu_setting: JSON.stringify({
            icon: 'calendar-check-fill',
            logo: '',
            tip: 'relevance',
            type: 'sys'
        })
    }))

    Plugins.save(Plugins.create({
        plugin_tag: '44444',
        plugin_name: '44444',
        is_menu: true,
        status: STATES.ACTIVATE, 
        menu_setting: JSON.stringify({
            icon: 'x-diamond-fill',
            logo: '',
            tip: 'relevance',
            type: 'sys'
        })
    }))

    Plugins.save(Plugins.create({
        plugin_tag: '55555',
        plugin_name: '55555',
        is_menu: true,
        status: STATES.ACTIVATE, 
        menu_setting: JSON.stringify({
            icon: 'exclude',
            logo: '',
            tip: 'relevance',
            type: 'sys'
        })
    }))
}